package com.bjb.vr.server.task;

import com.bjb.vr.common.utils.CanalTool;
import com.bjb.vr.common.utils.DateTimeUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @description:
 * @author: hujingbo
 * @create: 2022-08-02 10:24
 **/
@Slf4j
@Component
public class CleanDataTask {

    @Resource
    private JdbcTemplate jdbcTemplate;

    /**
     * 每五分钟执行一次
     */
    @Async
    @Scheduled(cron = "0 */5 * * * ?")
    public void cleanExecutedDataTask() {
        String startTime = DateTimeUtil.getBeforeHours(4);
        // 删除executed_sql表数据
        String cleanSyncStatement = CanalTool.getCleanSyncStatement(startTime);
        jdbcTemplate.execute(cleanSyncStatement);
        // 删除sync_data表数据
        String cleanStatement = CanalTool.getCleanStatement(startTime);
        jdbcTemplate.execute(cleanStatement);
    }
}
